package demo.rbac.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import demo.rbac.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserDao extends BaseMapper<User> {

  @Select("select r.role_name from user_role ru " +
          "left join role r on ru.role_id = r.id " +
          "where ru.user_id=#{id}"
  )
  List<String> getRolesByUserId(Long id);

  @Select("select p.code from user_role ru " +
          "left join role_permission rp on ru.role_id = rp.role_id " +
          "left join permission p on rp.permission_id = p.id"
  )
  List<String> getPermissionCodesByUserId(Long id);

}
